package com.atwork.wuhua.mvp.presenter;

import com.atwork.wuhua.base.BasePresenter;
import com.atwork.wuhua.base.BaseReq;
import com.atwork.wuhua.base.MyApplication;
import com.atwork.wuhua.bean.EvaluateBean;
import com.atwork.wuhua.bean.EvaluateDetailBean;
import com.atwork.wuhua.bean.MyWarBean;
import com.atwork.wuhua.mvp.Callback;
import com.atwork.wuhua.mvp.DataModel;
import com.atwork.wuhua.mvp.Token;
import com.atwork.wuhua.mvp.view.IEvaluateActivity;
import com.atwork.wuhua.utils.LogUtils;

public class EvaluatePresenter extends BasePresenter<IEvaluateActivity> {

    public void getLabels() {
        BaseReq req = new BaseReq();
        req.setKey("page", "1");
        DataModel.request(Token.API_LABELS)
                .params(req)
                .execute(new Callback<EvaluateBean>() {

                    public void onSuccess(String msg, EvaluateBean data) {
                        getView().setLabsls(data);
                        hideLoading();
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    public void postEvaluate(String reservation_id, float star, String labels) {
        if (star == 0) {
            showToast("请选择评价等级");
            return;
        }
        if (labels.length() == 0) {
            showToast("请选择评价标签");
            return;
        }
        showLoading();
        BaseReq req = new BaseReq();
        req.setKey("uuid", MyApplication.UUID);
        req.setKey("reservation_id", reservation_id);
        req.setKey("star", star + "");
        req.setKey("labels", labels);
        LogUtils.e("评价==》" + req.getString());
        DataModel.request(Token.API_EVALUATE)
                .params(req)
                .execute(new Callback<String>() {

                    public void onSuccess(String msg, String data) {
                        showToast("评价成功");
                        hideLoading();
                        getView().evaluateResult();
                    }

                    @Override
                    public void onFailure(String msg) {
                        showToast("评价失败，请重新评价");
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }


                });

    }

    public void getEvaluateDetail(String reservation_id) {
        BaseReq req = new BaseReq();
        req.setKey("reservation_id", reservation_id);
        DataModel.request(Token.API_EVALUATE_DETAIL)
                .params(req)
                .execute(new Callback<EvaluateDetailBean>() {

                    public void onSuccess(String msg, EvaluateDetailBean data) {
                        getView().setEvaluateDetail(data);
                        hideLoading();
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
